﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace StudentInfoSystem.UI.Views.Component;

public partial class SideMenu : UserControl
{

    private Button _oldSelectedButton;
    public SideMenu()
    {
        InitializeComponent();
        // 设置默认选中的按钮
        _oldSelectedButton = StudentListButton;
        SetSelectedButton(StudentListButton);
    }

    // 定义菜单项点击事件
    public event RoutedEventHandler? MenuItemClicked;

    // 处理所有菜单按钮的点击
    private void MenuButton_Click(object sender, RoutedEventArgs e)
    {
        if (sender is Button button)
        {
            // 更新选中的按钮
            SetSelectedButton(button);
            // 触发事件并传递Tag值作为菜单项标识
            MenuItemClicked?.Invoke(button.Name, e);
        }
    }


    // 设置选中的按钮
    private void SetSelectedButton(Button button)
    {
        _oldSelectedButton.Tag = "NoSelected";
        button.Tag = "Selected";
        _oldSelectedButton = button;
    }
}